package pres.moling.common.tool;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Random;

/**
 * 随机工具类
 *
 * @author moling
 */
public interface RandomHelper {


    /**
     * 生成指定区间的数
     */
    static int randomInt(int min, int max) {
        return new Random().nextInt(min, max);
    }


    /**
     * 生成指定长度的整数
     */
    static int randomInt(int length) {
        return new Random().nextInt(length);
    }

    /**
     * 生成指定字符集中生成指定长度的随机字符串
     */
    static String randomStr(int length, char... sc) {
        StringBuilder s = new StringBuilder();
        for (int i = 0; i < length; i++) {
            s.append(sc[randomInt(sc.length)]);
        }
        return s.toString();
    }

    static String randomDateStr(int length) {
        return LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE) + randomStr(length);
    }

    static String randomStr(int length) {
        return randomStr(length, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toCharArray());
    }


}
